package com.codingfuture.erp_system.service.impl;

import com.codingfuture.erp_system.dto.EmpDto;
import com.codingfuture.erp_system.entity.Dep;
import com.codingfuture.erp_system.entity.Emp;
import com.codingfuture.erp_system.mapper.EmpMapper;
import com.codingfuture.erp_system.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public Emp findById(Integer id) {
        return empMapper.findById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean delete(Integer id) {
        return empMapper.delete(id) != 0;
    }


    @Override
    public List<EmpDto> findByAll(EmpDto empDto) {
        return empMapper.findByAll(empDto);
    }

    @Override
    public List<Dep> finAll() {
        return empMapper.finAll();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insert(Emp emp) {
        return empMapper.insert(emp);
    }

    @Override
    public String userNameExist(String username) {
        return empMapper.userNameExist(username);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean update(Emp emp) {
        return empMapper.update(emp) != 0;
    }


}
